package com.doge.walknovel.business.home.profile.wallet

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.doge.walknovel.api.model.WalletDetailInfo
import com.doge.walknovel.core.base.adapters.AdapterCallback
import com.doge.walknovel.core.base.adapters.ITEM_CLICKED
import com.doge.wnpro.databinding.CellWalletHistoryBinding
import com.doge.walknovel.utils.getColor
import com.doge.walknovel.utils.setOnClickCallback
import com.doge.walknovel.utils.timeDesc

class WalletHistoryViewHolder(
    parent: ViewGroup,
    callback: AdapterCallback,
    private val binding: CellWalletHistoryBinding = CellWalletHistoryBinding.inflate(
        LayoutInflater.from(parent.context), parent, false),
) : RecyclerView.ViewHolder(binding.root) {
    init {
        itemView.setOnClickCallback {
            callback.invoke(ITEM_CLICKED, itemView.tag)
        }
    }

    fun bind(item: WalletDetailInfo) {
        itemView.tag = item
        binding.get.text = item.amount.toString()
        binding.get.setTextColor(getColor(if ((item.amount ?: 0f) > 0f) "#FF8DA5" else "#333333"))
        binding.info.text = item.title
        binding.desc.text = item.detail
        binding.timestamp.text = item.createTime?.timeDesc
    }
}